﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpinPlatformCtl : PlatformCtl
{

    SpriteRenderer spriteRenderer;
    HingeJoint2D joint;

    public override void Start()
    {
        base.Start();

        spriteRenderer = GetComponent<SpriteRenderer>();
        joint = GetComponent<HingeJoint2D>();

        RandomSpin();
    }

    public override void Update()
    {
        base.Update();
    }


    private void RandomSpin()
    {
        if (IsTurnLeft)
        {
            spriteRenderer.flipX = true;
            joint.limits = new JointAngleLimits2D
            {
                min = -89,
                max = 0
            };
        }
        else
        {
            spriteRenderer.flipX = false;
            joint.limits = new JointAngleLimits2D
            {
                min = 0,
                max = 89
            };
        }
    }

    
    bool IsTurnLeft
    {
        get => Random.Range(0f, 2f) < 1f;
    }
}
